import { _decorator, Component, Label, Vec3 } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('NumberSplitter')
export class NumberSplitter extends Component {

    @property(Label) 
    labelHundreds: Label | null = null;
    @property(Label) 
    labelTens: Label | null = null;
    @property(Label) 
    labelUnits: Label | null = null;

    // start()
    // {
    //     this.setNumber(65);
    // }

    public setNumber(value: number) {
        // 确保数字在有效范围内
        const num = Math.min(999, Math.max(0, Math.floor(value)));
        const padded = num.toString();

        // if (this.node.name == "NumNode_Hero") {
        //     if (padded.length == 1) {
        //         this.node.setPosition(new Vec3(78, 20, 0));
        //     }
        //     else if (padded.length == 2) {
        //         this.node.setPosition(new Vec3(65, 12, 0));
        //     }
        //     else if (padded.length == 3) {
        //         this.node.setPosition(new Vec3(50, 0, 0));
        //     }
        // }
        // else{
        //     if (padded.length == 1) {
        //         this.node.setPosition(new Vec3(118, 28, 0));
        //     }
        //     else if (padded.length == 2) {
        //         this.node.setPosition(new Vec3(104, 14, 0));
        //     }
        //     else if (padded.length == 3) {
        //         this.node.setPosition(new Vec3(87, 4, 0));
        //     }
        // }
        

        // 拆分到各个Label
        if (this.labelHundreds)
            this.labelHundreds.string = padded[0];
        if (this.labelTens) {
            if (padded.length > 1) {
                this.labelTens.string = padded[1];
                this.labelTens.node.active = true;
            }
            else {
                this.labelTens.node.active = false;
            }
        }
        if (this.labelUnits) {
            if (padded.length > 2) {
                this.labelUnits.string = padded[2];
                this.labelUnits.node.active = true;
            }
            else {
                this.labelUnits.node.active = false;
            }
        }
        
    }
}